const state = {
  language: localStorage.getItem('language') || 'zh',
  theme: ''
};

const mutations = {
  // 切换语言
  changLanguage(state, language) {
    state.language = language;
    localStorage.setItem('language', language);
  },
  // 初始化语言
  initLanguage(state) {
    let language = localStorage.getItem('language') || 'zh';
    localStorage.setItem('language', language);
    state.language = language;
  },
  // 初始化主题
  initTheme(state) {
    let theme = localStorage.getItem('theme') || '#3378FF';
    localStorage.setItem('theme', theme);
    state.theme = theme;
    let root = document.querySelector(':root');
    root.style.setProperty('--color-primary', theme);
  },
  // 设置主题
  setTheme(state, theme) {
    state.theme = theme;
    localStorage.setItem('theme', theme);
    let root = document.querySelector(':root');
    root.style.setProperty('--color-primary', theme);
  }
};

const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
